-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define error hint for insert
on DynamicIndexLens
.
#140
Conversation
Awesome! I like the message, as is. However if you want to shorten it one option would be to link the discussion in your other PR. |
Interesting, I wonder how this is causing failures on v1.6 |
yikes, I think we should then drop the hint on v1.6. |
Great! Both for this specific hint itself, and for setting the precedent :) Maybe, in the future we should turn methods that exist only to show user-friendly errors into error hints (eg Lines 177 to 183 in dc42b02
|
What are the pros and cons for having an error hint vs a detailed error message? |
@@ -10,6 +10,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | |||
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112" | |||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | |||
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" | |||
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I myself will use Accessors even with more deps, but not sure what others think.
Note that several existing deps can easily be turned into extensions, if not for the Julia ext precompilation bug. If that happens, only 4 actual deps would remain.
Personally, I think the (shortened) error message won't lose much without markdown.
Are there any existing markdown error hints in Julia?
But this is a minor point, fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW Markdown
is a stdlib so it's not particularly costly or weird to rely on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I can remove it too. I just like that it makes code snippets look a little distinct, and the REPL examples get syntax highlighting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe with this PR we should set the precedent for long and nicely formatted errorhints in Julia generally :) At least the Base ones are pretty minimal.
Don't know for certain, separation of concerns maybe? |
Mhh which concerns are separated here? |
One problem with defining a method and then making it error is that it makes interactively exploring an API (or just trying to look-before-you-leap) less reliable. e.g. if we did
then someone might do |
One is "arguments for the function are wrong" (then throw an error), another is "here's what you could do if we guess your intent correctly" (show an errorhint). |
One other reason that it's good to use error hints here rather than defining an error method is that defining error methods can cause method ambiguities. For example, if someone else defined the method
then it might end up being ambiguous with
even though the conflicting method is just a junk method we created to try and give more informative error messages |
Looks like the v1.6 failure is unrelated? |
Weird, it definitely passes on master. |
Aaah, I see! There's another |
Silly me. |
I think it's better to avoid overengineering, and keep a single message in a single place. As I understand, @jw3126 also likes the PR in its current state, so going to merge. |
Oh, I think an even more concrete pro of an error hint is that it goes in addition to the actual error message – not replaces it. Currently: julia> @set f((a=1,b=2)) = 3
ERROR: This should be unreachable. You probably need to overload
`Accessors.set(obj, ::typeof(f), val) Potentially without julia> @set f((a=1,b=2)) = 3
ERROR: MethodError: no method matching _set(::@NamedTuple{a::Int64, b::Int64}, ::typeof(f), ::Int64, ::Accessors.SetBased)
You probably need to overload `Accessors.set(obj, ::typeof(f), val)
Closest candidates are:
_set(::Any, ::Any, ::Any, ::Accessors.ModifyBased)
@ Accessors ~/.julia/dev/Accessors/src/optics.jl:187
_set(::Any, ::ComposedFunction, ::Any, ::Accessors.SetBased)
@ Accessors ~/.julia/dev/Accessors/src/optics.jl:191 It shows the same suggestion, but also prints which specific method was not found (ie what type |
These were needed a long time ago for inference reasons, which may no longer apply I guess. |
Alternative to #132
Here's what it looks like when a user hits the error:
I went kinda maximalist on the description, but if we want we can slim it down a lot.